<?php
if( ! defined('BASEPATH')) exit('No direct script access allowed');

class wallpage extends CI_Controller
{


	function __construct()
	{
		parent::__construct();
		// check if user logged in
		if(!$this->ion_auth->logged_in()){
			redirect('auth/login');
		}
		$this->load->library('form_validation');
		$this->load->model('user/wallpage_model');
	}
	function viewwall($id=null)
	{
		//$data['userid'] = $id;
		if(isset($id))
		{
			$user= $id;
		}else
		{
			$user=$this->session->userdata('user_id');		
		}
		$data['userid'] = $user;
		$data['designationbyid'] = $this->wallpage_model->designationbyid($user);
		$data['userdetails'] = $this->wallpage_model->userdetails($user);
		$data['coffeebyid'] = $this->wallpage_model->coffeebyid($user);
		$data['badgesid'] = $this->wallpage_model->badges_by_id($user);
		$data['badgesidarray'] = $this->wallpage_model->badges_by_id_array($user);
		$data['userpost'] = $this->wallpage_model->userpost($user);
		$data['followers'] = $this->wallpage_model->followers($user);
		$data['followersarray'] = $this->wallpage_model->followersarray($user);
		$data['thanksreceived'] = $this->wallpage_model->thanksreceived($user);
		$data['number_of_thanks'] = $this->wallpage_model->number_of_thanks($user);
		$data['number_of_stars'] = $this->wallpage_model->number_of_stars($user);
		$data['starsreceived'] = $this->wallpage_model->starsreceived($user);
		$data['user'] = $this->wallpage_model->get_user_details($this->session->userdata('user_id'));

		$meta['page_title'] = "Wall";
		$this->load->view('common/header',$meta);
		$this->load->view('user/view-wallpage',$data);
		$this->load->view('common/footer');

	}
	
	function wallpost()
	{	
			$users = $this->input->post('users');	
			$userto = $this->input->post('users');
			$userfrom = $this->session->userdata('user_id');	
			$date = date('Y/m/d H:i:s');
			$insert = array('from_user_id'=>$userfrom,
						'to_user_id'=>$userto,
						'content'=>$this->input->post('content'));
			$this->wallpage_model->post_insert($insert);
				redirect('user/wallpage/viewwall/'.$users);
	}
	
	function delete_wallpost($id)
	{
		
		//$id = $this->input->post('deletewall');
		$this->wallpage_model->delete_wallpost($id);
		redirect('user/wallpage/viewwall','refresh');
	}
	
	function follow()
	{	
	$users = $this->input->post('users');	
	$userfrom = $this->session->userdata('user_id');	
			if(isset($userfrom))
			{
				$follow=1;
			}
			$userto = $this->input->post('users');
			
			$insert = array('follower_id'=>$userfrom,
						'user_id'=>$userto,
						);
			$this->wallpage_model->follow_insert($insert);
			redirect('user/wallpage/viewwall/'.$users);
	}
	function thanks()
	{	
	$users = $this->input->post('users');	
	$userfrom = $this->session->userdata('user_id');	
			if(isset($userfrom))
			{
				$thank=1;
			}
			$userto = $this->input->post('users');
			
		/*	$date = date('Y/m/d H:i:s');*/
			$insert = array('from_user_id'=>$userfrom,
						'to_user_id'=>$userto);
			$this->wallpage_model->thank_insert($insert);
			redirect('user/wallpage/viewwall/'.$users);
	}
}	
